<div id="app">
    <section class="content-header">
        <h1>
            <small>商品租期编辑</small>
        </h1>

    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-info">
                    <div class="box-header with-border">


                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                                <a href="/admin/goods/goodsLease?goods_id={{$goods['goods_id']}}" class="btn btn-sm btn-default" title="商品租期展示"><i class="fa fa-list"></i><span class="hidden-xs">&nbsp;商品租期展示</span></a>
                            </div>
                        </div>

                        <span>
    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>
    <a class="btn btn-sm btn-primary" onclick="javascript:history.go(-1);" title="返回"> <span class="hidden-xs"> 返回</span></a>
  </span>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form id="addForm" action="/admin/goods/goodsAdd" method="post" accept-charset="UTF-8" class="form-horizontal" enctype="multipart/form-data" pjax-container>
                        <div class="box-body">
                            <div class="fields-group">

                                <div class="form-group  ">
                                    <label for="cha_id" class="col-sm-2  control-label">商品名称</label>
                                    <div class="col-sm-8">
                                        <input type="text"   value="{{$goods['goods_name']}}" class="form-control" readonly />
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="sku" class="col-sm-2  control-label">商品sku</label>
                                    <div class="col-sm-8">
                                        @if($sku)
                                            @foreach($sku as $v)
                                                <label class="radio-inline">
                                                    @if($v['id']==$info['goods_sku_id'])
                                                        <input type="radio" checked name="sku" value="{{$v['id']}}" class="minimal "   />&nbsp;
                                                    @else
                                                        <input type="radio" name="sku" value="{{$v['id']}}" class="minimal "   />&nbsp;
                                                    @endif
                                                </label>

                                                <input type="text" class="form-control" readonly value="商品属性规格：【{{$v['sku_str']}}】  商品总价：{{$v['goods_price']}} , 商品官方价：{{$v['goods_official_price']}}">
                                                <br />
                                            @endforeach
                                        @endif
                                    </div>
                                </div>




                                <div class="form-group  ">
                                    <label for="rent_price" class="col-sm-2  control-label">总租金</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <span class="input-group-addon">￥</span>
                                            <input style="width: 120px" type="text" id="rent_price" name="rent_price" value="{{$info['rent_price']}}" class="form-control rent_price" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="deposit_price" class="col-sm-2  control-label">押金</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <span class="input-group-addon">￥</span>
                                            <input style="width: 120px" type="text" id="deposit_price" name="deposit_price" value="{{$info['deposit_price']}}" class="form-control deposit_price"   />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="buyout_price" class="col-sm-2  control-label">买断金</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <span class="input-group-addon">￥</span>
                                            <input style="width: 120px" type="text" id="buyout_price" name="buyout_price" value="{{$info['buyout_price']}}" class="form-control buyout_price"   />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="term_num" class="col-sm-2  control-label">租期期数</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input   style="width: 100px;display: inline-block" type="text" id="term_num" name="term_num" value="{{$info['term_num']}}" class="form-control term_num"   />

                                            <button type="button"  style="margin-top:5px;color:#f9f9f9;width:80px;position:relative;float: right;background:#3b8ab8;height:30px;border-radius: 5px;padding:3px;border: 1px solid #3b8ab8;" onclick="setZuqi()">设置</button>

                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="term_num" class="col-sm-2  control-label"></label>
                                    <div class="col-sm-8" id="zuqi_html" style="border: 1px solid #a1cbef;padding:5px;">
                                        @if($term)
                                            @foreach($term as $k=>$v)
                                                <div style="margin:5px;">
                                                    <div style="display:inline-block;text-align:center;width:60px;height:30px;background: #a1cbef;line-height: 30px;">第{{$k+1}}期</div>  本期租金：<input type="text" value="{{$v['price']}}" name="price[]" value="'.$price.'" style="margin-right:30px;">  天数: <input name="day_num[]"  value="30"  type="text" value="{{$v['day_num']}}" />
                                                </div>
                                            @endforeach
                                        @endif

                                    </div>
                                </div>

                                {{--<div class="form-group  " >--}}
                                {{--<label for="term_num" class="col-sm-2  control-label">租期</label>--}}
                                {{--<div class="col-sm-8" style="border:1px solid red;">--}}

                                {{--<div class="input-group">--}}
                                {{--<input style="width: 120px;margin:5px;" type="text" id="buyout_price" name="buyout_price" value="" class="form-control buyout_price" placeholder="输入 本期租金" />--}}
                                {{--<input   style="width: 100px;margin:5px;" type="text"   name="term_num" value="" class="form-control term_num"   />--}}

                                {{--</div>--}}
                                {{--<div class="input-group">--}}
                                {{--<input style="width: 120px;margin:5px;" type="text" id="buyout_price" name="buyout_price" value="" class="form-control buyout_price" placeholder="输入 本期租金" />--}}

                                {{--<input   style="width: 100px;margin:5px;" type="text"   name="term_num" value="" class="form-control term_num"   />--}}

                                {{--</div>--}}
                                {{--<div class="input-group">--}}
                                {{--<input style="width: 120px;margin:5px;" type="text" id="buyout_price" name="buyout_price" value="" class="form-control buyout_price" placeholder="输入 本期租金" />--}}

                                {{--<input   style="width: 100px;margin:5px;" type="text"   name="term_num" value="" class="form-control term_num"   />--}}

                                {{--</div>--}}
                                {{--</div>--}}
                                {{--</div>--}}










                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            @csrf
                            <input type="hidden" id="id" name="id" value="{{$info['id']}}">
                            <input type="hidden" id="goods_id" name="goods_id" value="{{$goods['goods_id']}}">
                            <div class="col-md-2">
                            </div>
                            <div class="col-md-8">
                                <div class="btn-group pull-right">
                                    <button type="button" onclick="tijiao()" class="btn btn-primary">提交</button>
                                </div>

                                <div class="btn-group pull-left">
                                    <button type="reset" class="btn btn-warning">重置</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

            </div></div>
    </section>
</div>
<script data-exec-on-popstate>
    $(function () {
        $("input.img").fileinput({"overwriteInitial":true,"initialPreviewAsData":true,"browseLabel":"\u6d4f\u89c8","showRemove":false,"showUpload":false,"dropZoneEnabled":false,"deleteExtraData":{"goods_img_list":"_file_del_","_file_del_":"","_token":"Kq6b1qbgSwE02ACOgZOsO9QeD99PSWROQgk10d1w","_method":"PUT"},"deleteUrl":"http:\/\/www.laras.com\/admin\/goods\/","allowedFileTypes":["image"]});
        $('.after-submit').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChecked', function () {
            $('.after-submit').not(this).iCheck('uncheck');
        });

        $('.sku').iCheck({checkboxClass:'icheckbox_minimal-blue'});
        $('.rent_price').inputmask({"alias":"currency","radixPoint":".","prefix":"","removeMaskOnSubmit":true});
        $('.deposit_price').inputmask({"alias":"currency","radixPoint":".","prefix":"","removeMaskOnSubmit":true});
        $('.buyout_price').inputmask({"alias":"currency","radixPoint":".","prefix":"","removeMaskOnSubmit":true});
        $('.term_num:not(.initialized)')
            .addClass('initialized')
            .bootstrapNumber({
                upClass: 'success',
                downClass: 'primary',
                center: true
            });

        var cha_id=$("#cha_id").val();
        if(cha_id>0){
            getPid(ob,cha_id);
        }

        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });
    });

    function setZuqi(){
        var num=$("#term_num").val();
        var price=$("#rent_price").val();
        if(num>0){
            $.ajax({
                url:'/admin/goods/getZuqiHtml',
                type:'get',
                data:{term_num:num,rent_price:price},
                dataType:'json',
                success:function (m) {
                    if(m.status==1){
                        $("#zuqi_html").html(m.data.html);
                    }
                }
            });
        }
    }


    function tijiao(){
        var data=new FormData($("#addForm")[0]);
        var goods_id=$("#goods_id").val();
        $.ajax({
            url:"/admin/goods/goodsLeaseEdit",
            type:'post',
            data:data,
            dataType:'json',
            processData: false,
            contentType: false,
            success:function(m){
                if(m.status==1){
                    toastr.success(m.message);
                    window.location.href='/admin/goods/goodsLease?goods_id='+goods_id;
                }else{
                    swal(m.message, '', 'error');
                }
            }
        });
    }
</script>